package com.wz.project.pda.service;

import com.wz.framework.web.domain.AjaxResult;
import com.wz.project.api.barcode.domain.Barcode;
import com.wz.project.api.barcode.domain.BarcodeInfo;
import com.wz.project.api.barcode.domain.MatnrInfo;
import com.wz.project.api.barcode.mapper.*;
import com.wz.project.api.barcode.service.BarcodeService;
import com.wz.project.api.sap.controller.SapController;
import com.wz.project.api.tmsMatnr.domain.TmMatnr;
import com.wz.project.api.tmsMatnr.mapper.TmMatnrMapper;
import com.wz.project.api.tmsMatnr.service.ITmMatnrService;
import com.wz.project.barcodeMsg.domain.BarcodeMsg;
import com.wz.project.barcodeMsg.service.IBarcodeMsgService;
import com.wz.project.bas.product.domain.Product;
import com.wz.project.bas.product.service.IProductService;
import com.wz.project.inStock.stockin.domain.InStockin;
import com.wz.project.inStock.stockin.mapper.InStockinMapper;
import com.wz.project.inStock.stockin.service.IInStockinService;
import com.wz.project.inStock.stockindetail.domain.InStockinDetail;
import com.wz.project.inStock.stockindetail.mapper.InStockinDetailMapper;
import com.wz.project.inStock.stockindetail.service.IInStockinDetailService;
import com.wz.project.mydo.domain.MydoJob;
import com.wz.project.mydo.domain.MydoJobDetail;
import com.wz.project.mydo.mydojob.mapper.MydoJobMapper;
import com.wz.project.mydo.mydojob.service.IMydoJobService;
import com.wz.project.mydo.mydojobdetail.mapper.JobDetailMapper;
import com.wz.project.mydo.mydojobdetail.service.IJobDetailService;
import com.wz.project.outStock.stockout.domain.OutStockout;
import com.wz.project.outStock.stockout.service.IOutStockoutService;
import com.wz.project.outStock.stockoutdetail.mapper.OutStockoutDetailMapper;
import com.wz.project.outStock.stockoutdetail.service.IOutStockoutDetailService;
import com.wz.project.outTray.outTray.service.IOutTrayMsgService;
import com.wz.project.sap.DN.domain.ZflWmsGetDn;
import com.wz.project.sap.DN.service.IZflWmsGetDnService;
import com.wz.project.sap.DN_POST_DN.domain.ZflWmsDnPostDn;
import com.wz.project.sap.DN_POST_DN.service.IZflWmsDnPostDnService;
import com.wz.project.sap.POST_TMDATA_SERIAL.domain.YppRfcPostTmdataSerial;
import com.wz.project.sap.POST_TMDATA_SERIAL.service.IYppRfcPostTmdataSerialService;
import com.wz.project.sap.POST_TMDATA_TMINTERF.domain.YppRfcPostTmdataTminterf;
import com.wz.project.sap.POST_TMDATA_TMINTERF.service.IYppRfcPostTmdataTminterfService;
import com.wz.project.stock.stock.mapper.BasStockMapper;
import com.wz.project.stock.stockdetail.domain.BasStockDetail;
import com.wz.project.stock.stockdetail.service.IBasStockDetailService;
import com.wz.project.surebarcode.sureBarcode.domain.Surebarcode;
import com.wz.project.surebarcode.sureBarcode.service.ISurebarcodeService;
import com.wz.project.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureQuery;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class PdaServicePkImpl implements PdaServicePk {

    @Autowired
    private EntityManager entityManager;
    @Autowired
    private IOutStockoutDetailService outStockoutDetailService;
    @Autowired
    private IOutStockoutService outStockoutService;
    @Autowired
    private IInStockinService inStockinService;
    @Autowired
    private IInStockinDetailService inStockinDetailService;
    @Autowired
    PdaService pdaService;
    @Autowired
    SapController sapController;
    @Autowired
    ITmMatnrService matnrService;
    @Autowired
    IMydoJobService mydoJobService;
    @Autowired
    IJobDetailService mydoJobDetailService;
    @Autowired
    IZflWmsGetDnService ZflWmsGetDnService;
    @Autowired
    IProductService productService;
    @Autowired
    IZflWmsDnPostDnService zflWmsDnPostDnService;
    @Autowired
    IBarcodeMsgService barcodeMsgService;
    @Autowired
    BarcodeService barcodeService;
    @Autowired
    IBasStockDetailService basStockDetailService;
    @Autowired
    private TmMatnrMapper tmMatnrMapper;
    @Autowired
    ISurebarcodeService surebarcodeService;
    @Autowired
    MydoJobMapper mydoJobMapper;
    @Autowired
    ITmMatnrService tmMatnrService;

    @Autowired
    IYppRfcPostTmdataTminterfService yppRfcPostTmdataTminterfService;
    @Resource
    IYppRfcPostTmdataSerialService yppRfcPostTmdataSerialService;

    @Override
    public AjaxResult barcodeMsgAdd(BarcodeMsg barcodeMsg) {
        AjaxResult ajaxResult = new AjaxResult();
        String fbarcode = barcodeMsg.getBarcode();
        BarcodeMsg barcodeMsg1 = barcodeMsgService.selectBarcodeMsgById(fbarcode);
        if (barcodeMsg1 == null) {
            barcodeMsgService.insertBarcodeMsg(barcodeMsg);
            ajaxResult.put("res", "数据采集成功");
        } else {
            ajaxResult.put("res", "条码数据重复");
        }
        return ajaxResult;
    }

    @Override
    public AjaxResult addStock(String trayCode, String cargoSpaceId, String barcode) {
        String msg = "";
        AjaxResult ajaxResult = new AjaxResult();
        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_add_stock");
        StoredProcedureQuery parameter = storedProcedureQuery
                .registerStoredProcedureParameter("v_cargoSpaceId", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_tray_code", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_barcode", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_result", String.class, ParameterMode.OUT);

        parameter.setParameter("v_cargoSpaceId", cargoSpaceId);
        parameter.setParameter("v_tray_code", trayCode);
        parameter.setParameter("v_barcode", barcode);

        //执行
        storedProcedureQuery.execute();
        //获取返回结果
        String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

        if ("1".equals(result)) {
            msg = "扫描重复！";
        } else if ("2".equals(result)) {
            msg = "货位不存在！";
        } else if ("3".equals(result)) {
            msg = "托盘不在该储位！";
        } else if ("4".equals(result)) {
            msg = "扫描信息不存在！";
        } else if ("9".equals(result)) {
            msg = "操作失败，请重试！";
        } else if ("10".equals(result)) {
            msg = "操作成功！";
        }
        return ajaxResult.put("res", msg);

    }

    @Override
    public Map selectTmsMsgSH(TmMatnr tmMatn) {
        String fbarcode = tmMatn.getFbarcode();
        String stockInId = tmMatn.getInStockId();

        Map map = new HashMap<>();
        //查询是否同步交货单号
        ZflWmsGetDn zflWmsGetDn = ZflWmsGetDnService.selectZflWmsGetDnById1(String.format("%010d", Long.parseLong(stockInId)));
        if (zflWmsGetDn == null) {
            sapController.getDNData(String.format("%010d", Long.parseLong(stockInId)), "", "");
        }
        //查询条码是否已入库
        BasStockDetail basStockDetail = basStockDetailService.selectBasStockDetailById(fbarcode);
        if (basStockDetail != null) {
            map.put("isnull", "该条码已入库，无需重复扫描");
            return map;
        }
        //查询计算该单据所有子件总数
        InStockinDetail inStockinDetail1 = pdaService.selectInstock(String.format("%010d", Long.parseLong(stockInId)));
        if (inStockinDetail1 != null) {
            map.put("qty", inStockinDetail1.getQuantity());
        }
        //查询条码是否已扫描未入库
        TmMatnr tmMatnr1 = pdaService.selectTmMatnrByFid(fbarcode);
        if (tmMatnr1 != null) {
            //按照单据，物料子件分组统计各物料扫描数量
            List<TmMatnr> tmMatnr = matnrService.selectTmMatnrByInstock(String.format("%010d", Long.parseLong(stockInId)));
            if (tmMatnr.size() > 0) {
                map.put("matnrList", tmMatnr);
            }
            //查询该单据已扫描总数
            List<TmMatnr> tmMatnrl = matnrService.selectTmMatnrByStickInIde(String.format("%010d", Long.parseLong(stockInId)));
            map.put("qtyout", tmMatnrl.size());
            map.put("isnull", "该条码已扫描，无需重复扫描");
            return map;
        }
        //查询物料子母件信息
        Barcode barcode = null;
        try {
            Barcode barcode1 = pdaService.selectBarcodeBd(fbarcode);
            if (barcode1 == null) {
                barcode = barcodeService.selectBarcodeByIdHs(fbarcode);
                if (barcode != null) {
                    pdaService.saveBarcode(barcode);
                }
            } else {
                barcode = barcode1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isnull", "条码平台异常！！！");
            return map;
        }
        String stockinGuid = "";
        if (barcode != null) {

            //生产订单号（成品）在v_tm_matnr_minfo只有一条信息
            if (barcode.getAufnr() != null && barcode.getAufnr() != "") {
                stockinGuid = barcode.getAufnr();
                map.put("isnull", "该条码非配套物资无需收货");
                return map;
            } else {
                //采购订单号（配套）在v_tm_matnr_minfo有多条信息
                stockinGuid = String.format("%010d", Long.parseLong(stockInId));
            }
            //用物料和单据号查询子单据信息，如果有此物料的单据
            String barcodes = String.format("%018d", Long.parseLong(barcode.getMatnr().split("-")[0]));

            List<InStockinDetail> inStockinDetails = pdaService.selectInstockDetail(stockinGuid, barcode.getMatnr());

            if (inStockinDetails.size() > 0) {
                InStockinDetail inStockinDetail = inStockinDetails.get(0);
                List<MatnrInfo> matnrInfoList = null;

                List<MatnrInfo> matnrInfoLists = pdaService.selectMatnrInfobd(barcode.getMatnr().split("-")[0]);
                if (matnrInfoLists.size() == 0) {
                    //从v_tm_matnr_minfo表中用母件码查询所有齐套件信息
                    matnrInfoList = pdaService.selectMatnrInfo(barcode.getMatnr().split("-")[0]);
                    if (matnrInfoList.size() > 0) {
                        for (MatnrInfo m : matnrInfoList) {
                            pdaService.insetMatnrInfo(m);
                        }
                    } else {
                        map.put("isnull", "此物料信息子母件条码平台未维护");
                        return map;
                    }
                } else {
                    matnrInfoList = matnrInfoLists;
                }
                MatnrInfo matnrInfo = pdaService.selectMatnrBdById(barcode.getMatnr());
                TmMatnr tmMatnr = new TmMatnr();
                tmMatnr.setMatnr(matnrInfo.getMatnr());
                tmMatnr.setMaktx(matnrInfo.getMaktx());
                tmMatnr.setMatnrMain(barcodes);
                tmMatnr.setYkutxt(matnrInfo.getYkutxt());
                tmMatnr.setEwbez(matnrInfo.getEwbez());
                tmMatnr.setFunit(matnrInfo.getFunit());
                tmMatnr.setFpackunit(matnrInfo.getFpackunit());
                tmMatnr.setFflag(matnrInfo.getFflag());
                tmMatnr.setFnum(matnrInfo.getFnum());
                tmMatnr.setBarcode(barcode.getFbarcode());
                tmMatnr.setFbarcode(barcode.getFbarcode());
                tmMatnr.setStatus(-1);
                tmMatnr.setLotNo(new SimpleDateFormat("yyyyMMdd").format(new Date()));
                tmMatnr.setInStockId(inStockinDetail.getStockinGuid());
                tmMatnr.setInStockDId(inStockinDetail.getPrintDate());
                tmMatnr.setOutStockId(inStockinDetail.getStockStatus().split("-")[0]);
                tmMatnr.setOutStockDId(inStockinDetail.getStockStatus().split("-")[1]);
                tmMatnr.setFid(inStockinDetail.getCargoNo());
                matnrService.insertTmMatnr(tmMatnr);

                map.put("isnull", "该物料子件扫描成功");
                pdaService.updateInstockDetail(stockinGuid, matnrInfo.getMatnr(), inStockinDetail.getStockinDetailId());
                List<TmMatnr> tmMatnrl = matnrService.selectTmMatnrByStickInIde(String.format("%010d", Long.parseLong(stockInId)));
                List<TmMatnr> tmMatnrls = matnrService.selectTmMatnrByInstock(String.format("%010d", Long.parseLong(stockInId)));

                map.put("matnrList", tmMatnrls);
                map.put("qtyout", tmMatnrl.size());
            } else {
                List<TmMatnr> tmMatnr = matnrService.selectTmMatnrByInstock(String.format("%010d", Long.parseLong(stockInId)));
                if (tmMatnr.size() > 0) {
                    map.put("matnrList", tmMatnr);
                    map.put("isnull", "扫描子件已达上限");
                } else {
                    map.put("isnull", "无对应的收货单");
                }
                List<TmMatnr> tmMatnrl = matnrService.selectTmMatnrByStickInIde(String.format("%010d", Long.parseLong(stockInId)));

                map.put("qtyout", tmMatnrl.size());


                return map;
            }
        } else {
            map.put("isnull", "此条码条码平台未进行维护");
        }
        return map;
    }

    @Override
    public AjaxResult sureSH(TmMatnr tmMatn) {
        String stockInId = tmMatn.getInStockId();
        AjaxResult ajaxResult = new AjaxResult();
        stockInId = String.format("%010d", Long.parseLong(stockInId));
        InStockinDetail inStockinDetail1 = pdaService.selectInstock(stockInId);
        int fnum = 0;
        if (inStockinDetail1 != null) {
            fnum = inStockinDetail1.getQuantity().intValue();
        }
        List<TmMatnr> tmMatnrs = matnrService.selectTmMatnrByStickInIde(stockInId);
        int saomiaosize = matnrService.selectTmMatnrGroupProduct(stockInId);
        int instockincount = pdaService.selectCount(stockInId);
        if (tmMatnrs.size() < fnum || saomiaosize < instockincount) {
            ajaxResult.put("status", "该条码未齐套，无法收货");
            return ajaxResult;
        }

        for (TmMatnr tmMatnr : tmMatnrs) {
            if (tmMatnr != null && tmMatnr.getStatus() == -1 && "1".equals(tmMatnr.getFflag())) {
                String productLotNo = "";//是否批次管理
                String productXlh = "";//序列号
                Product product = productService.selectProductByProductId(String.format("%018d", Long.parseLong(tmMatnr.getMatnr().split("-")[0])));
                if (product != null) {
                    productLotNo = product.getSpecialFlag();
                    productXlh = product.getProductFlag();
                }
                ZflWmsGetDn zflWmsGetDn = new ZflWmsGetDn();
                zflWmsGetDn.setMATNR(StringUtil.Stringadd(tmMatnr.getMatnr().split("-")[0]));
                zflWmsGetDn.setVBELN(tmMatnr.getInStockId());
                zflWmsGetDn.setPOSNR(tmMatnr.getInStockDId());
                List<ZflWmsGetDn> zflWmsGetDns = ZflWmsGetDnService.selectZflWmsGetDnList(zflWmsGetDn);
                for (ZflWmsGetDn zflWmsGetDna : zflWmsGetDns) {
                    String lotNo = "";
                    ZflWmsDnPostDn zflWmsDnPostDn = new ZflWmsDnPostDn();
                    if ("X".equals(productLotNo)) {
                        zflWmsDnPostDn.setCHARG(tmMatnr.getLotNo());
//                        zflWmsDnPostDn.setCHARG(new SimpleDateFormat("yyyyMMdd").format(new Date()));
                    }
                    if ("X".equals(productXlh)) {
                        zflWmsDnPostDn.setSERNR(tmMatnr.getFbarcode().substring(4, tmMatnr.getFbarcode().length()));
                        zflWmsDnPostDn.setLFIMG(tmMatnr.getFnum().toString());
                    } else {
                        zflWmsDnPostDn.setLFIMG(zflWmsGetDna.getLFIMG());
                    }

                    zflWmsDnPostDn.setZEILE(tmMatnr.getInStockDId());
                    zflWmsDnPostDn.setVBELN(zflWmsGetDna.getVBELN());
                    zflWmsDnPostDn.setPOSNR(tmMatnr.getInStockDId());
                    zflWmsDnPostDn.setMATNR(zflWmsGetDna.getMATNR());
                    zflWmsDnPostDn.setPIKMG("0");
                    zflWmsDnPostDn.setWERKS(zflWmsGetDna.getWERKS());
                    zflWmsDnPostDn.setLGORT(zflWmsGetDna.getLGORT());
                    zflWmsDnPostDn.setVRKME(zflWmsGetDna.getVRKME());

                    int size = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn).size();
                    zflWmsDnPostDn.setStatus("-1");
                    if (size == 0) {
                        zflWmsDnPostDnService.insertZflWmsDnPostDn(zflWmsDnPostDn);
                    }
                }

                ZflWmsDnPostDn zflWmsDnPostDn = new ZflWmsDnPostDn();
                zflWmsDnPostDn.setVBELN(stockInId);
                zflWmsDnPostDn.setStatus("-1");
                int size = zflWmsDnPostDnService.selectZflWmsDnPostDnCount(zflWmsDnPostDn);
                int i = ZflWmsGetDnService.selectZflWmsGetDn(String.format("%010d", Long.parseLong(stockInId)));
                if (size == i) {
                    zflWmsDnPostDn.setStatus("0");
                    zflWmsDnPostDnService.updateZflWmsDnPostDnStatus(zflWmsDnPostDn);
                    pdaService.updatemMatnrs(stockInId);
                }
                ajaxResult.put("status", "收货成功");
            } else if (tmMatnr != null && tmMatnr.getStatus() == 0) {
                ajaxResult.put("status", "已收货");
            }
        }
        return ajaxResult;
    }

    @Override
    public Map autoAllocation(TmMatnr tmMatnr) {
        String stockin_guid = tmMatnr.getInStockId();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        stockin_guid = String.format("%010d", Integer.parseInt(stockin_guid));
        ZflWmsGetDn zflWmsGetDn = ZflWmsGetDnService.selectZflWmsGetDnById1(stockin_guid);
        if (zflWmsGetDn == null) {
            sapController.getDNData(stockin_guid, "", "");
        }
        OutStockout outStockout = outStockoutService.selectOutStockoutById(stockin_guid);
        String stockOutId[] = new String[1];
        if (outStockout != null) {
            stockOutId[0] = outStockout.getStockoutId();
            return outStockoutService.autoAllocation(stockOutId);
        } else {
            resultMap.put("errorInfo", "没有对应交货单");
            return resultMap;
        }
    }

    @Override
    public AjaxResult sureOut(TmMatnr tmMatn) {
        String fbarcode = tmMatn.getFbarcode();
        String stockin_guid = tmMatn.getInStockId();
        AjaxResult ajaxResult = new AjaxResult();
        stockin_guid = String.format("%010d", Long.parseLong(stockin_guid));
        Surebarcode surebarcode = new Surebarcode();
        surebarcode.setFbarcode(fbarcode);
        surebarcode.setStockoutGuid(stockin_guid);
        List<Surebarcode> surebarcodes = surebarcodeService.selectSurebarcodeList(surebarcode);

        if (surebarcodes.size() > 0) {
            Surebarcode surebarcode1 = surebarcodes.get(0);
            MatnrInfo matnrInfo = null;
            matnrInfo = pdaService.selectMatnrBdById(surebarcode1.getProductDetailId());
            if (matnrInfo == null) {
                List<MatnrInfo> matnrInfoList = pdaService.selectMatnrInfo(surebarcode1.getProductDetailId().split("-")[0]);
                if (matnrInfoList.size() > 0) {
                    for (MatnrInfo m : matnrInfoList) {
                        pdaService.insetMatnrInfo(m);
                    }
                }
            }
            matnrInfo = pdaService.selectMatnrBdById(surebarcode1.getProductDetailId());
            if (matnrInfo != null) {
                MatnrInfo matnrInfo1 = pdaService.selectMatnrBdById(surebarcode1.getProductDetailId().split("-")[0]);
                List<TmMatnr> tmMatnrs = pdaService.selectTmMatnrByfbarcode(fbarcode.substring(0, 18), fbarcode.substring(13, 22));
                if (tmMatnrs.size() < matnrInfo.getFnum().intValue() + 1) {
                    TmMatnr tmMatnr1 = pdaService.selectTmMatnrByFid(fbarcode);
                    if (tmMatnr1 == null) {
                        int count = pdaService.selectTmMatnrByFCount(surebarcode1.getProductDetailId(), surebarcode1.getStockoutGuid(), surebarcode1.getProductId());
                        if (count == 0) {

                            TmMatnr tmMatnr = new TmMatnr();
                            tmMatnr.setMatnr(matnrInfo.getMatnr());
                            tmMatnr.setMaktx(matnrInfo.getMaktx());
                            tmMatnr.setMatnrMain(surebarcode1.getProductId());
                            tmMatnr.setYkutxt(matnrInfo.getYkutxt());
                            tmMatnr.setEwbez(matnrInfo.getEwbez());
                            tmMatnr.setFunit(matnrInfo.getFunit());
                            tmMatnr.setFpackunit(matnrInfo.getFpackunit());
                            tmMatnr.setFflag(matnrInfo.getFflag());
                            tmMatnr.setFnum(matnrInfo.getFnum());
                            tmMatnr.setBarcode("");
                            tmMatnr.setFbarcode(fbarcode);
                            tmMatnr.setFid(surebarcode1.getBarcode());
                            tmMatnr.setStatus(-1);
                            tmMatnr.setLotNo(surebarcode1.getLotNo());
                            tmMatnr.setInStockId(surebarcode1.getStockoutGuid());
                            tmMatnr.setInStockDId(surebarcode1.getVGPOS());
                            matnrService.insertTmMatnr(tmMatnr);
                            List<TmMatnr> tmMatnrss = pdaService.selectTmMatnrByfbarcode(fbarcode.substring(0, 18), fbarcode.substring(13, 22));
                            for (TmMatnr tmMatnra : tmMatnrss) {

                                if (tmMatnra != null && tmMatnra.getStatus() == -1 && "1".equals(tmMatnra.getFflag())) {
                                    String productLotNo = "";//是否批次管理
                                    String productXlh = "";//序列号
                                    Product product = productService.selectProductByProductId(String.format("%018d", Long.parseLong(tmMatnra.getMatnr().split("-")[0])));
                                    if (product != null) {
                                        productLotNo = product.getSpecialFlag();
                                        productXlh = product.getProductFlag();
                                    }
                                    ZflWmsGetDn zflWmsGetDn = new ZflWmsGetDn();
                                    zflWmsGetDn.setMATNR(String.format("%018d", Long.parseLong(tmMatnra.getMatnr().split("-")[0])));
                                    zflWmsGetDn.setVBELN(tmMatnra.getInStockId());
                                    List<ZflWmsGetDn> zflWmsGetDns = ZflWmsGetDnService.selectZflWmsGetDnList(zflWmsGetDn);
                                    for (ZflWmsGetDn zflWmsGetDna : zflWmsGetDns) {
                                        String lotNo = "";
                                        ZflWmsDnPostDn zflWmsDnPostDn = new ZflWmsDnPostDn();

                                        zflWmsDnPostDn.setZEILE(zflWmsGetDna.getPOSNR());
                                        zflWmsDnPostDn.setVBELN(zflWmsGetDna.getVBELN());
                                        zflWmsDnPostDn.setPOSNR(zflWmsGetDna.getPOSNR());
                                        zflWmsDnPostDn.setMATNR(zflWmsGetDna.getMATNR());
                                        zflWmsDnPostDn.setWERKS(zflWmsGetDna.getWERKS());
                                        zflWmsDnPostDn.setLGORT(zflWmsGetDna.getLGORT());
                                        zflWmsDnPostDn.setVRKME(zflWmsGetDna.getVRKME());

                                        if ("X".equals(productLotNo)) {
                                            zflWmsDnPostDn.setCHARG(tmMatnr.getLotNo());
                                            int size = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn).size();

                                            zflWmsDnPostDn.setLFIMG(matnrInfo.getFnum().toString());
                                            zflWmsDnPostDn.setPIKMG(matnrInfo.getFnum().toString());
                                            zflWmsDnPostDn.setStatus("-1");
                                            if (size == 0) {
                                                zflWmsDnPostDnService.insertZflWmsDnPostDn(zflWmsDnPostDn);
                                            } else {
                                                ZflWmsDnPostDn zflWmsDnPostDna1 = new ZflWmsDnPostDn();
                                                zflWmsDnPostDna1.setZEILE(zflWmsGetDna.getPOSNR());
                                                zflWmsDnPostDna1.setVBELN(zflWmsGetDna.getVBELN());
                                                ZflWmsDnPostDn zflWmsDnPostDn1 = zflWmsDnPostDnService.selectZflWmsDnPostDn(zflWmsDnPostDna1);

                                                zflWmsDnPostDna1.setLFIMG((String.valueOf(new BigDecimal(zflWmsDnPostDn1.getLFIMG()).intValue() + 1)));
                                                zflWmsDnPostDna1.setPIKMG((String.valueOf(new BigDecimal(zflWmsDnPostDn1.getPIKMG()).intValue() + 1)));
                                                zflWmsDnPostDnService.updateZflWmsDnPostDn(zflWmsDnPostDna1);
                                            }
                                        }
                                        if ("X".equals(productXlh)) {
                                            zflWmsDnPostDn.setSERNR(tmMatnr.getFbarcode().substring(4, fbarcode.length()));
                                            int size = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn).size();
                                            zflWmsDnPostDn.setStatus("-1");

                                            zflWmsDnPostDn.setLFIMG(matnrInfo.getFnum().toString());
                                            zflWmsDnPostDn.setPIKMG(matnrInfo.getFnum().toString());
                                            if (size == 0) {
                                                zflWmsDnPostDnService.insertZflWmsDnPostDn(zflWmsDnPostDn);
                                            }
                                        }
                                    }
                                }
                                int i = pdaService.selectCountOut(stockin_guid);
                                ZflWmsDnPostDn zflWmsDnPostDn = new ZflWmsDnPostDn();
                                zflWmsDnPostDn.setVBELN(stockin_guid);
                                zflWmsDnPostDn.setStatus("-1");
                                int size = zflWmsDnPostDnService.selectZflWmsDnPostDnCount(zflWmsDnPostDn);
                                if (size == i) {
                                    zflWmsDnPostDn.setStatus("0");
                                    zflWmsDnPostDnService.updateZflWmsDnPostDnStatus(zflWmsDnPostDn);
                                }

                            }
                            BasStockDetail basStockDetail = basStockDetailService.selectBasStockDetailById(fbarcode);
                            if (basStockDetail != null) {
                                basStockDetailService.insertBasStockDetailfinish(basStockDetail);
                                basStockDetailService.deleteBasStockDetailById(fbarcode);
                            }
                            ajaxResult.put("status", "出货成功");
//                            surebarcode1.getBarcode()
                            outStockoutDetailService.updateOutStockoutDetailBYId(surebarcode1.getBarcode());
                            if (tmMatnrss.size() == matnrInfo.getFnum().intValue()) {
                                TmMatnr tmMatnr11 = new TmMatnr();
                                tmMatnr11.setStatus(0);
                                tmMatnr11.setBarcode(surebarcode.getBarcode());
                                tmMatnr11.setInStockId(surebarcode.getStockoutGuid());
                                matnrService.updateTmMatnr(tmMatnr11);
                            }
                        } else {
                            ajaxResult.put("status", "该单据的物料子件数量已达分配上限");
                        }
                    } else {
                        ajaxResult.put("status", "该条码已扫描，请勿重复扫描");
                    }
                }
            }
        } else {
            ajaxResult.put("status", "或者条码已出库,或扫描条码不在对应托盘");
        }
        pdaService.finishPK();
        return ajaxResult;
    }

    @Override
    public AjaxResult insetMydoJob(String trayCode, String quantity, String fbarcode) {

        String msg = "";
        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_auto_in_product");
        StoredProcedureQuery parameter = storedProcedureQuery
                .registerStoredProcedureParameter("v_barcode_detail", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_in_quantity", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_tray_code", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_result", String.class, ParameterMode.OUT);
        parameter.setParameter("v_barcode_detail", fbarcode);
        parameter.setParameter("v_in_quantity", quantity);
        parameter.setParameter("v_tray_code", trayCode);
        //执行
        storedProcedureQuery.execute();
        //获取返回结果
        String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

        if ("1".equals(result)) {
            msg = "该托盘已有作业！";
        } else if ("2".equals(result)) {
            msg = "子件标签不存在！";
        } else if ("5".equals(result)) {
            msg = "子件标签已扫描！";
        } else if ("4".equals(result)) {
            msg = "子件标签已扫描！";
        } else if ("6".equals(result)) {
            msg = "该托盘有出库作业！";
        } else if ("9".equals(result)) {
            msg = "操作失败，请重试！";
        } else if ("10".equals(result)) {
            msg = "操作成功！";
        }

        if ("10".equals(result)) {
            return AjaxResult.success(msg);
        } else {
            return AjaxResult.error(msg);
        }
    }

    @Override
    public AjaxResult insetMydoJobcppk(String trayCode, String quantity, String fbarcode, String cargoSpaceId) {

        String msg = "";
        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_auoto_in_productP");
        StoredProcedureQuery parameter = storedProcedureQuery
                .registerStoredProcedureParameter("v_barcode_detail", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_in_quantity", Integer.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_tray_code", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_cargo_space_id", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_result", String.class, ParameterMode.OUT);

        parameter.setParameter("v_barcode_detail", fbarcode);
        parameter.setParameter("v_in_quantity", quantity);
        parameter.setParameter("v_tray_code", trayCode);
        parameter.setParameter("v_cargo_space_id", cargoSpaceId);

        //执行
        storedProcedureQuery.execute();
        //获取返回结果
        String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

        if ("1".equals(result)) {
            msg = "该托盘已有作业！";
        } else if ("2".equals(result)) {
            msg = "子件标签不存在！";
        } else if ("3".equals(result)) {
            msg = "平库不存在此货位！";
        } else if ("9".equals(result)) {
            msg = "操作失败，请重试！";
        } else if ("10".equals(result)) {
            msg = "操作成功！";
        } else if ("4".equals(result)) {
            msg = "扫描重复！";
        }

        if ("10".equals(result)) {
            return AjaxResult.success(msg);
        } else {
            return AjaxResult.error(msg);
        }
    }

    @Override
    public int selectJobByTray(String trayCode, String status) {
        return mydoJobMapper.selectJobBytrayCode(trayCode, status);
    }

    @Override
    public int updateJobStatus(String trayCode) {
        return mydoJobMapper.updateByTray(trayCode);
    }

    @Override
    public AjaxResult insertMydoJobFinish(String cargoSpaceId, String fbarcode, Integer quantity, String trayCode) {
        String msg = "";
        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_auoto_in_productP");
        StoredProcedureQuery parameter = storedProcedureQuery
                .registerStoredProcedureParameter("v_barcode_detail", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_in_quantity", Integer.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_tray_code", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_cargo_space_id", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_result", String.class, ParameterMode.OUT);

        parameter.setParameter("v_barcode_detail", fbarcode);
        parameter.setParameter("v_in_quantity", quantity);
        parameter.setParameter("v_tray_code", trayCode);
        parameter.setParameter("v_cargo_space_id", cargoSpaceId);

        //执行
        storedProcedureQuery.execute();
        //获取返回结果
        String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

        if ("1".equals(result)) {
            msg = "该托盘已有作业！";
        } else if ("2".equals(result)) {
            msg = "子件标签不存在！";
        } else if ("3".equals(result)) {
            msg = "平库不存在此货位！";
        } else if ("9".equals(result)) {
            msg = "操作失败，请重试！";
        } else if ("10".equals(result)) {
            msg = "操作成功！";
        } else if ("4".equals(result)) {
            msg = "扫描重复！";
        }

        if ("10".equals(result)) {
            return AjaxResult.success(msg);
        } else {
            return AjaxResult.error(msg);
        }
    }

    @Override
    public void completeJob(String trayCode) {
        pdaService.completeJob(trayCode);
    }

    @Override
    public Map selectTmsMsgCg(BasStockDetail basStockDetail) {
        String fbarcode = basStockDetail.getFbarcode();
        String trayCode = basStockDetail.getTrayCode();
        Map map = new HashMap<>();
        Barcode barcode = null;
        Barcode barcode1 = pdaService.selectBarcodeBd(fbarcode);
        if (barcode1 == null) {
            barcode = barcodeService.selectBarcodeByIdHs(fbarcode);
            if (barcode != null) {
                pdaService.saveBarcode(barcode);
            }
        } else {
            barcode = barcode1;
        }
        String stockinGuid = "";
        if (barcode != null) {
            TmMatnr tmMatnr1 = pdaService.selectTmMatnrByFid(fbarcode);
            if (tmMatnr1 != null && tmMatnr1.getStatus() > 1) {
                map.put("status", tmMatnr1.getStatus());
                return map;
            } else if (tmMatnr1 == null) {
                map.put("status", "此条码未收货");
            }
            if (tmMatnr1 != null) {
                ZflWmsDnPostDn zflWmsDnPostDn = zflWmsDnPostDnService.selectZflWmsDnPostDnByPAI(tmMatnr1.getMatnrMain(), tmMatnr1.getInStockId());
                if (zflWmsDnPostDn != null && "X".equals(zflWmsDnPostDn.getTYPE()) && zflWmsDnPostDn.getPRUEFLOS() != null) {
                    map.put("status", "此条码检验不通过，不能入库");
                }
                if (zflWmsDnPostDn != null && "0".equals(zflWmsDnPostDn.getTYPE()) && zflWmsDnPostDn.getPRUEFLOS() != null) {
                    map.put("status", "此条码未检验，不能入库");
                }
                if (zflWmsDnPostDn == null || (zflWmsDnPostDn != null && "0".equals(zflWmsDnPostDn.getStatus()))) {
                    map.put("status", "此条码未检验，不能入库");
                }
            }
            //用物料和单据号查询子单据信息，如果有此物料的单据
//            String barcodes = String.format("%018d", Long.parseLong(barcode.getMatnr().split("-")[0]));
            List<MatnrInfo> matnrInfoList = pdaService.selectMatnrInfobd(barcode.getMatnr().split("-")[0]);


            if (matnrInfoList.size() == 0) {
                map.put("status", "此条码母子件信息未维护");
            } else {
                map.put("nowMatnr", barcode.getMatnr());

                map.put("quantity", barcode.getFnum());
            }
            //查询tm_matnr表里是否已有此条
            //从t_barcode_info表中查询fid值


        } else {
            map.put("status", "此条码未收货1");
        }
        List<MydoJobDetail> lists = pdaService.selectJobDet(trayCode);
        if (lists.size() > 0) {
            map.put("matnrList", lists);//成品只能查出一条母件信息
            map.put("qtyout", lists.size());
        } else {
            map.put("qtyout", 0);
        }
        return map;
    }

    @Override
    public AjaxResult jobTpAdd(String trayCode, int quantity) {
        String msg = "";
        AjaxResult ajaxResult = new AjaxResult();
        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_auto_in_tp_one");
        StoredProcedureQuery parameter = storedProcedureQuery
                .registerStoredProcedureParameter("v_tray_code", String.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_quantity", Integer.class, ParameterMode.IN)
                .registerStoredProcedureParameter("v_result", Integer.class, ParameterMode.OUT);

        parameter.setParameter("v_tray_code", trayCode);
        parameter.setParameter("v_quantity", 7);

        //执行
        storedProcedureQuery.execute();
        //获取返回结果
        String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

        if ("1".equals(result)) {
            msg = "托盘已有入库作业！";
        } else if ("2".equals(result)) {
            msg = "托盘已有库存！";
        } else if ("3".equals(result)) {
            msg = "该口已有入库作业！";
        } else if ("4".equals(result)) {
            msg = "扫描信息不存在！";
        } else if ("9".equals(result)) {
            msg = "操作失败，请重试！";
        } else if ("10".equals(result)) {
            msg = "操作成功！";
        }
        return ajaxResult.put("res", msg);
    }

    @Override
    public AjaxResult jobTpOut(String exit_id, int quantity) {
        String msg = "";
        AjaxResult ajaxResult = new AjaxResult();
        for (int i = 0; i < quantity; i++) {

            StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("proc_auto_out_tp");
            StoredProcedureQuery parameter = storedProcedureQuery
                    .registerStoredProcedureParameter("v_type", String.class, ParameterMode.IN)
                    .registerStoredProcedureParameter("v_exit_id", String.class, ParameterMode.IN)
                    .registerStoredProcedureParameter("v_result", String.class, ParameterMode.OUT);

            parameter.setParameter("v_type", "2");
            parameter.setParameter("v_exit_id", exit_id);

            //执行
            storedProcedureQuery.execute();
            //获取返回结果
            String result = (String) storedProcedureQuery.getOutputParameterValue("v_result");

            if ("1".equals(result)) {
                msg = "库存中已经没有空托盘！";
            } else if ("9".equals(result)) {
                msg = "操作失败，请重试！";
            } else if ("10".equals(result)) {
                msg = "操作成功！";
            }
        }
        return ajaxResult.put("res", msg);
    }

    @Override
    public Map selectTmsMsgSc(BasStockDetail basStockDetail) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String fbarcode = basStockDetail.getFbarcode();
        if (fbarcode.length() < 13) {
            resultMap.put("result", "条码扫描异常！！！");
        }
        String barcode = basStockDetail.getFbarcode().substring(0, 13);
        Barcode barcodes = null;
        try {
            Barcode barcode1 = pdaService.selectBarcodeBd(fbarcode);
            if (barcode1 == null) {
                barcodes = barcodeService.selectBarcodeByIdHs(fbarcode);
                if (barcode != null) {
                    pdaService.saveBarcode(barcodes);
                }
            } else {
                barcodes = barcode1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", "条码平台异常！！！");
            return resultMap;
        }
        if (barcodes != null) {
            if (barcodes.getAufnr() == null || "".equals(barcodes.getAufnr())) {
                resultMap.put("result", "该条码生产单号为空或非生产条码");
                return resultMap;
            }
//            InStockin inStockin = inStockinService.selectInStockinById(barcodes.getAufnr());
//            if(inStockin == null){
//                resultMap.put("result", "该条码无对应生产单据");
//                return resultMap;
//            }
            String matnr_m = barcodes.getMatnr().split("-")[0];
            List<MatnrInfo> matnrInfoLists = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m));
            if (matnrInfoLists.size() == 0) {
                //从v_tm_matnr_minfo表中用母件码查询所有齐套件信息
                List<MatnrInfo> matnrInfoList = pdaService.selectMatnrInfo(StringUtil.Stringdel(matnr_m));
                if (matnrInfoList.size() > 0) {
                    for (MatnrInfo m : matnrInfoList) {
                            pdaService.insetMatnrInfo(m);
                    }
                }
            }
            List<MatnrInfo> matnrInfoList = null;
            List<MatnrInfo> matnrInfos = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m));
            if (matnrInfos.size() == 1) {
                matnrInfoList = matnrInfos;
            } else if (matnrInfos.size() > 1) {
                matnrInfoList = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m + "-"));
            }
            List<TmMatnr> matnrList = tmMatnrService.selectTmMatnrByFbarcode(fbarcode);
            if (matnrList.size() > 0) {
                resultMap.put("matnrList", matnrList);
                resultMap.put("result", "1");
                return resultMap;
            }

            TmMatnr tmMatnr = new TmMatnr();
            tmMatnr.setMatnr(barcodes.getMatnr());
            tmMatnr.setFbarcode(barcodes.getFbarcode());
            tmMatnr.setFnum(new BigDecimal(barcodes.getFnum()));
            tmMatnr.setFunit(barcodes.getFunit());
            tmMatnr.setFflag(barcodes.getFflag());
            tmMatnr.setMatnrMain(StringUtil.Stringadd(barcodes.getMatnr().split("-")[0]));
            tmMatnr.setBarcode(barcodes.getFbarcode().substring(0, 13));
            tmMatnr.setStatus(-1);
            tmMatnr.setLotNo(new SimpleDateFormat("yyyyMMdd").format(new Date()));
            tmMatnr.setInStockId(barcodes.getAufnr());
            tmMatnrService.insertTmMatnr(tmMatnr);
            List<TmMatnr> matnrList1 = tmMatnrService.selectTmMatnrByFbarcode(fbarcode);
            resultMap.put("matnrList", matnrList1);
            resultMap.put("result", "1");
        } else {
            resultMap.put("result", "该条码条码平台未维护");
            return resultMap;
        }
        return resultMap;
    }

    @Override
    public Map selectTmsMsgScDj(BasStockDetail basStockDetail) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String fbarcode = basStockDetail.getFbarcode();
        if (fbarcode.length() < 13) {
            resultMap.put("result", "条码扫描异常！！！");
            return resultMap;
        }
        String barcode = basStockDetail.getFbarcode().substring(0, 13);
        Barcode barcodes = null;
        try {
            Barcode barcode1 = pdaService.selectBarcodeBd(fbarcode);
            if (barcode1 == null) {
                barcodes = barcodeService.selectBarcodeByIdHs(fbarcode);
                if (barcode != null) {
                    pdaService.saveBarcode(barcodes);
                }
            } else {
                barcodes = barcode1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", "条码平台异常！！！");
            return resultMap;
        }
        if (barcodes != null) {
            if (barcodes.getAufnr() == null || "".equals(barcodes.getAufnr())) {
                resultMap.put("result", "该条码生产单号为空或非生产条码");
                return resultMap;
            }
            InStockin inStockin = inStockinService.selectInStockinById(barcodes.getAufnr());
            if (inStockin == null) {
                resultMap.put("result", "该条码无对应生产单据");
                return resultMap;
            }
            InStockinDetail inStockinDetail = new InStockinDetail();
            inStockinDetail.setStockinId(inStockin.getStockinId());
            inStockinDetail.setStatus("1");
            List<InStockinDetail> inStockinDetails = inStockinDetailService.selectInStockinDetailList(inStockinDetail);
            for (InStockinDetail inStockinDetail1 : inStockinDetails) {

                String matnr_m = barcodes.getMatnr().split("-")[0];
                List<MatnrInfo> matnrInfoLists = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m));
                if (matnrInfoLists.size() == 0) {
                    //从v_tm_matnr_minfo表中用母件码查询所有齐套件信息
                    List<MatnrInfo> matnrInfoList = pdaService.selectMatnrInfo(StringUtil.Stringdel(matnr_m));
                    if (matnrInfoList.size() > 0) {
                        for (MatnrInfo m : matnrInfoList) {
                                pdaService.insetMatnrInfo(m);
                        }
                    }
                }
                List<MatnrInfo> matnrInfoList = null;
                List<MatnrInfo> matnrInfos = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m));
                if (matnrInfos.size() == 1) {
                    matnrInfoList = matnrInfos;
                } else if (matnrInfos.size() > 1) {
                    matnrInfoList = pdaService.selectMatnrInfobd(StringUtil.Stringdel(matnr_m + "-"));
                }
                List<TmMatnr> matnrList = tmMatnrService.selectTmMatnrByFbarcode(fbarcode);
                if (matnrList.size() > 0) {
                    resultMap.put("matnrList", matnrList);
                    resultMap.put("result", "1");
                    return resultMap;
                }

                TmMatnr tmMatnr = new TmMatnr();
                tmMatnr.setMatnr(barcodes.getMatnr());
                tmMatnr.setFbarcode(barcodes.getFbarcode());
                tmMatnr.setFnum(new BigDecimal(barcodes.getFnum()));
                tmMatnr.setFunit(barcodes.getFunit());
                tmMatnr.setFflag(barcodes.getFflag());
                tmMatnr.setMatnrMain(StringUtil.Stringadd(barcodes.getMatnr().split("-")[0]));
                tmMatnr.setBarcode(barcodes.getFbarcode().substring(0, 13));
                tmMatnr.setStatus(-1);
                tmMatnr.setLotNo(new SimpleDateFormat("yyyyMMdd").format(new Date()));
                tmMatnr.setInStockId(barcodes.getAufnr());
                if(!"-".equals(inStockinDetail1.getStockStatus())) {
                    tmMatnr.setOutStockId(inStockinDetail1.getStockStatus().split("-")[0]);
                    tmMatnr.setOutStockDId(inStockinDetail1.getStockStatus().split("-")[1]);
                }
                tmMatnr.setInStockDId(inStockinDetail1.getStockinDetailId());
                tmMatnr.setFid(inStockinDetail1.getCargoNo());
                tmMatnrService.insertTmMatnr(tmMatnr);
                List<TmMatnr> matnrList1 = tmMatnrService.selectTmMatnrByFbarcode(fbarcode);
                resultMap.put("matnrList", matnrList1);
                resultMap.put("result", "1");
                List<TmMatnr> matnrList2 = tmMatnrService.selectTmMatnrBybarcode(barcodes.getFbarcode().substring(0, 13));

                if(matnrInfos.size()==matnrList2.size() ){
                    String replace = UUID.randomUUID().toString().replace("-", "");
                    YppRfcPostTmdataTminterf yppRfcPostTmdataTminterf = new YppRfcPostTmdataTminterf();
                    yppRfcPostTmdataTminterf.setMANDT("800");
                    yppRfcPostTmdataTminterf.setZDOCNO(replace);
                    yppRfcPostTmdataTminterf.setZSAPDOCNO(barcodes.getAufnr());
                    yppRfcPostTmdataTminterf.setZDOCTP("A");
                    yppRfcPostTmdataTminterf.setZBUSTP("101");
                    yppRfcPostTmdataTminterf.setBUDAT(new SimpleDateFormat("yyyyMMdd").format(new Date()));
                    yppRfcPostTmdataTminterf.setMATNR(StringUtil.Stringadd(barcodes.getMatnr().split("-")[0]));
                    yppRfcPostTmdataTminterf.setERFMG("1");
                    yppRfcPostTmdataTminterf.setWERKS("2240");
                    yppRfcPostTmdataTminterf.setZLOC_I(inStockinDetail1.getCargoNo());
                    yppRfcPostTmdataTminterf.setZOPRTER("LKWMS");
                    yppRfcPostTmdataTminterf.setZPSTDT(new Date());
                    yppRfcPostTmdataTminterf.setZPSTTM(new Date());
                    yppRfcPostTmdataTminterf.setBATCH(new SimpleDateFormat("yyyyMMdd").format(new Date()));
                    yppRfcPostTmdataTminterf.setStatus("10");
                    YppRfcPostTmdataSerial yppRfcPostTmdataSerial = new YppRfcPostTmdataSerial();
                    yppRfcPostTmdataSerial.setMANDT("800");
                    yppRfcPostTmdataSerial.setSERIALNO(barcodes.getFbarcode().substring(0, 13));
                    yppRfcPostTmdataSerial.setMATDOC_ITM("1");
                    yppRfcPostTmdataSerial.setMATNR(StringUtil.Stringadd(barcodes.getMatnr().split("-")[0]));
                    yppRfcPostTmdataSerial.setZDOCNO(replace);
                    yppRfcPostTmdataTminterfService.insertYppRfcPostTmdataTminterf(yppRfcPostTmdataTminterf);
                    yppRfcPostTmdataSerialService.insertYppRfcPostTmdataSerial(yppRfcPostTmdataSerial);
                }
            }
        } else {
            resultMap.put("result", "该条码条码平台未维护");
            return resultMap;
        }
        return resultMap;
    }

    @Override
    public Map selectMsgTrayCode(BasStockDetail basStockDetail) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        List<MydoJobDetail> mydoJobDetails = new ArrayList<>();
        MydoJob mydoJob = mydoJobMapper.selectJob(basStockDetail.getTrayCode());
        if (mydoJob != null) {
            if ("0".equals(mydoJob.getStatus())) {
                MydoJobDetail mydoJobDetail = new MydoJobDetail();
                mydoJobDetail.setJobId(mydoJob.getJobId());
                mydoJobDetails = mydoJobDetailService.selectJobDetailList(mydoJobDetail);
            }
        }
        resultMap.put("matnrList", mydoJobDetails);

        return resultMap;
    }

    @Override
    public void finishPK() {
        HashMap<String, Object> map = new HashMap<>();
        tmMatnrMapper.finishPK(map);
    }

    @Override
    public void wms_data_in_del() {
        HashMap<String, Object> map = new HashMap<>();
        tmMatnrMapper.finishPK(map);
    }

    @Override
    public void wcs_mantr() {
        List<BasStockDetail> basStockDetails = basStockDetailService.selectBasStockDetailListall();
        for(BasStockDetail basStockDetail:basStockDetails) {
            List<MatnrInfo> matnrInfoLists = pdaService.selectMatnrInfobd(StringUtil.Stringdel(basStockDetail.getProductId()));
            if (matnrInfoLists.size() == 0) {
                //从v_tm_matnr_minfo表中用母件码查询所有齐套件信息
                List<MatnrInfo> matnrInfoList = pdaService.selectMatnrInfo(StringUtil.Stringdel(basStockDetail.getProductId()));
                if (matnrInfoList.size() > 0) {
                    for (MatnrInfo m : matnrInfoList) {
                        pdaService.insetMatnrInfo(m);
                    }
                }
            }
        }
    }
}
